#include "GraphicWorld.h"

using namespace Graphic;

GraphicWorld::GraphicWorld(void)
{

	mRoot = new Ogre::Root("plugins_d.cfg");
	Ogre::ConfigFile cf;
    cf.load("resources_d.cfg");

    
	Ogre::RenderSystem* renderSystem = mRoot->getRenderSystemByName("Direct3D9 Rendering Subsystem");
	mRoot->setRenderSystem(renderSystem);
	
	mWindow = mRoot->initialise( true, "OgreApp Render Window" );
	
	//mRoot->initialise(false);

	renderSystem->setConfigOption("Full Screen", "No");
	renderSystem->setConfigOption("Video Mode", "1024 x 768 @ 32-bit colour");

	mSceneManager = mRoot->createSceneManager(Ogre::ST_GENERIC, "DefaultScnManager");

	Ogre::RenderWindow *mRenderWin =  mRoot->initialise( true, "OgreApp Render Window" );//Ogre::Root::getSingletonPtr()->createRenderWindow("OgreWrapperControl", 800, 600, false, &iMisc);


	Ogre::ConfigFile configFile;

#ifdef _DEBUG
			configFile.load("resources_d.cfg");
#else
			configFile.load("resources.cfg");
#endif

	Ogre::ConfigFile::SectionIterator sectionIter = configFile.getSectionIterator();
	Ogre::String sectionName, typeName, dataname;

	while (sectionIter.hasMoreElements())
	{
		sectionName = sectionIter.peekNextKey();
		Ogre::ConfigFile::SettingsMultiMap* settings = sectionIter.getNext();
		Ogre::ConfigFile::SettingsMultiMap::iterator it;
		for (it = settings->begin(); it != settings->end(); ++it)
		{
			typeName = it->first;
			dataname = it->second;

			Ogre::ResourceGroupManager::getSingleton().addResourceLocation(dataname, typeName, sectionName);
		}
	}
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();


	mCamera = mSceneManager->createCamera("PlayerCam");

    // Position it at 500 in Z direction
    mCamera->setPosition(Ogre::Vector3(0, 0, 80));
    // Look back along -Z
    mCamera->lookAt(Ogre::Vector3(0, 0, -300));
    mCamera->setNearClipDistance(5);

    mCameraManager = new OgreBites::SdkCameraMan(mCamera);
	mCameraManager = new OgreBites::SdkCameraMan(mCamera);//new GameGraphics::CameraManager(mSceneManager);
//	mFrameListener->SetCameraManager(mCameraManager);
 
	Ogre::Viewport* vp = mRenderWin->addViewport(mCamera);

	vp->setBackgroundColour(Ogre::ColourValue(0,0,0.2f));

	mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));

}


GraphicWorld::~GraphicWorld(void)
{
}
